package com.ship.dispatch.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.ship.common.core.constant.CacheConstants;
import com.ship.common.core.utils.DateUtils;
import com.ship.common.core.utils.bean.BeanUtils;
import com.ship.common.redis.service.RedisService;
import com.ship.dispatch.bean.*;
import com.ship.dispatch.bean.HomePage.ConHomePageAll;
import com.ship.dispatch.bean.HomePage.ConHomePageShow;
import com.ship.dispatch.bean.boats.QueryShipInsideInfo;
import com.ship.dispatch.bean.boats.info.*;
import com.ship.dispatch.bean.sy.SyNewRecord;
import com.ship.dispatch.bo.SmShipRentAnalysisBo;
import com.ship.dispatch.mapper.SpBoatsShipCountMapper;
import com.ship.dispatch.mapper.SpDispatchSchemeExecuteMapper;
import com.ship.dispatch.mapper.SpInformationListMapper;
import com.ship.dispatch.service.*;
import com.ship.dispatch.model.Vo.MonthlyExecutionCompleteVo;
import com.ship.dispatch.service.decisionAnalysis.SmShipRentService;
import com.ship.dispatch.util.DateErgodicUtil;
import com.ship.dispatch.vo.report.ShapeUnifyVo;
import org.apache.commons.collections4.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class HomePageServiceImpl implements HomePageService {
    private static final Logger logger = LoggerFactory.getLogger(HomePageServiceImpl.class);

    @Autowired
    private SpInformationListMapper informationListMapper;

    @Autowired
    private SpDispatchSchemeExecuteMapper dispatchSchemeExecuteMapper;

    @Autowired
    private BoatsVoyageMessageService boatsVoyageMessageService;

    @Resource
    private RedisService redisService;

    @Autowired
    private SmShipRentService smShipRentService;

    @Autowired
    private SpBoatsShipCountMapper boatsShipCountMapper;

    @Autowired
    private SyNewRecordService syNewRecordService;

    @Autowired
    private ConShippingService conShippingService;

    @Autowired
    private SpDispatchSchemeExecuteService spDispatchSchemeExecuteService;

    @Autowired
    private ConHomePageServer conHomePageServer;

    /**
     * LNG 船舶数量
     *
     * @param startDate 时间格式 YYYY-MM-dd
     * @param endDate   时间格式 YYYY-MM-dd
     * @return
     */
    public List<ShapeUnifyVo> queryTotalByShipStatus(String startDate, String endDate) {
        this.updateBoatsShipCount();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        for (int i = 0; i <= 11; i++) {
            DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = null;
            String yearMonth = "";
            try {
                date = dateFormat1.parse(startDate);
                Date startDateNew = DateUtil.offsetMonth(date, i);
                yearMonth = DateUtils.parseDateToStr("yyyy-MM-dd", startDateNew);
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
            shapeUnifyVos.add(new ShapeUnifyVo("0", yearMonth.split("-")[0] + "-" + yearMonth.split("-")[1], ""));
        }
        List<ShapeUnifyVo> shapeUnifyVos1 = informationListMapper.queryShipCount(startDate.split("-")[0] + "-" + startDate.split("-")[1], endDate.split("-")[0] + "-" + endDate.split("-")[1]);
        if (null != shapeUnifyVos1 && shapeUnifyVos1.size() > 0) {
            shapeUnifyVos.stream().forEach(s -> {
                List<ShapeUnifyVo> shapeUnifyNewVos = shapeUnifyVos1.stream().filter(p -> p.getValue().equals(s.getValue())).collect(Collectors.toList());
                if (null != shapeUnifyNewVos && shapeUnifyNewVos.size() > 0) {
                    s.setKey(shapeUnifyNewVos.get(0).getKey());
                }
            });
        }
        return shapeUnifyVos;
    }

    private void updateBoatsShipCount() {
        ShapeUnifyVo shapeUnifyVo = informationListMapper.queryShipCountLast();
        if (null != shapeUnifyVo) {
            Date date = new Date();
            String yearMonth = DateUtils.parseDateToStr("yyyy-MM-dd", date);
            String month = yearMonth.split("-")[1];
            String monthShape = shapeUnifyVo.getValue().split("-")[1];
            if(!month.equals(monthShape)){
                SpBoatsShipCount boatsShipCount = new SpBoatsShipCount();
                boatsShipCount.setCountNumber(Integer.valueOf(shapeUnifyVo.getKey()));
                boatsShipCount.setCreateDate(DateUtils.parseDate(yearMonth.split("-")[0]+"-"+yearMonth.split("-")[1]+"-01"));
                boatsShipCountMapper.insert(boatsShipCount);
            }
        }
    }


    /**
     * 月度执行完成货量
     *
     * @param startDate 时间格式 YYYY-MM-dd
     * @param endDate   时间格式 YYYY-MM-dd
     * @return
     */
    public List<ShapeUnifyVo> queryExecutionComplete(String startDate, String endDate) {
        Date currentDate = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        String yearMonth = dateFormat.format(currentDate);
        String yearMonthDay = dateFormat1.format(currentDate);

        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        for (int i = 0; i <= 11; i++) {
            DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = null;
            String yearMonth1 = "";
            try {
                date = dateFormat2.parse(startDate);
                Date startDateNew = DateUtil.offsetMonth(date, i);
                yearMonth1 = DateUtils.parseDateToStr("yyyy-MM-dd", startDateNew);
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
            shapeUnifyVos.add(new ShapeUnifyVo("0", yearMonth1.split("-")[0] + "-" + yearMonth1.split("-")[1], ""));
        }
        List<MonthlyExecutionCompleteVo> monthlyExecutionCompleteVos = dispatchSchemeExecuteMapper.queryExecutionComplete(startDate, endDate);
        if (null != monthlyExecutionCompleteVos && monthlyExecutionCompleteVos.size() > 0) {
            shapeUnifyVos.stream().forEach(s -> {
                List<MonthlyExecutionCompleteVo> monthlyExecutionCompleteVoList = monthlyExecutionCompleteVos.stream().filter(p -> p.getRealityMonth().equals(s.getValue())).collect(Collectors.toList());
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                if (null != monthlyExecutionCompleteVoList && monthlyExecutionCompleteVoList.size() > 0) {
                    MonthlyExecutionCompleteVo monthlyExecutionCompleteVo = monthlyExecutionCompleteVoList.get(0);
                    if (null != monthlyExecutionCompleteVo) {
                        if (yearMonth.equals(monthlyExecutionCompleteVo.getRealityMonth())) {
                            String num = dispatchSchemeExecuteMapper.queryExecutionCurrentDayComplete(yearMonth + "-01", yearMonthDay);
                            shapeUnifyVo.setKey(num);
                            shapeUnifyVo.setValue(monthlyExecutionCompleteVo.getRealityMonth());
                        } else {
                            shapeUnifyVo.setKey(monthlyExecutionCompleteVo.getRealityTotal());
                            shapeUnifyVo.setValue(monthlyExecutionCompleteVo.getRealityMonth());
                        }
                    }
                }
            });
        }

        return shapeUnifyVos;
    }

    public List<QueryShipInsideInfo> queryShipCountryInside(String startDate, String endDate){
        List<QueryShipInsideInfo> resultList = boatsVoyageMessageService.queryShipCountryInside(startDate, endDate);
        if (CollectionUtil.isNotEmpty(resultList)){
            resultList.forEach(item -> {
                BigDecimal result = new BigDecimal(item.getCountTotal()).divide(new BigDecimal(10000));
                item.setCountTotal(result.setScale(0, RoundingMode.HALF_UP).toString());
            });
        }
        return resultList;
    }

    /**
     * TOP5 进口港及其进口量(单位：万吨)
     *
     * @return
     */
    public List<QueryPortEntranceInfo> shipPortEntranceVolume(String startDate, String endDate) {
        List<QueryPortEntranceInfo> portEntranceList = new ArrayList<>();
        List<QueryBoatsVoyageMessagesInfo> portList = boatsVoyageMessageService.queryhipPortEntranceVolume(startDate, endDate);
        if (CollectionUtil.isNotEmpty(portList)) {
            List<QueryBoatsVoyageMessagesInfo> voyageMessagesInfos = portList.stream().limit(5).collect(Collectors.toList());
            voyageMessagesInfos.forEach(item -> {
                QueryPortEntranceInfo queryPortEntranceInfo = new QueryPortEntranceInfo();
                queryPortEntranceInfo.setPortName(item.getPortName());
                BigDecimal exportVolumeTotal = item.getExportVolumeTotal();
                if (exportVolumeTotal != null) {
                    BigDecimal result = exportVolumeTotal.divide(new BigDecimal(10000));
                    queryPortEntranceInfo.setCountTotal(result.setScale(0, RoundingMode.HALF_UP).toString());
                } else {
                    queryPortEntranceInfo.setCountTotal(new BigDecimal(0).toString());
                }
                portEntranceList.add(queryPortEntranceInfo);
            });
        }
        return portEntranceList;
    }

    /**
     * TOP5 出口港及其出口量(单位：万吨)
     *
     * @return
     */
    public List<QueryPortEntranceInfo> shipPortExportVolume(String startDate, String endDate) {
        List<QueryPortEntranceInfo> portEntranceList = new ArrayList<>();
        List<QueryBoatsVoyageMessagesInfo> portList = boatsVoyageMessageService.queryShipPortExportVolume(startDate, endDate);
        if (CollectionUtil.isNotEmpty(portList)) {
            List<QueryBoatsVoyageMessagesInfo> voyageMessagesInfos = portList.stream().limit(5).collect(Collectors.toList());
            voyageMessagesInfos.forEach(item -> {
                QueryPortEntranceInfo queryPortEntranceInfo = new QueryPortEntranceInfo();
                queryPortEntranceInfo.setPortName(item.getPortName());
                BigDecimal exportVolumeTotal = item.getExportVolumeTotal();
                if (exportVolumeTotal != null) {
                    BigDecimal result = exportVolumeTotal.divide(new BigDecimal(10000));
                    queryPortEntranceInfo.setCountTotal(result.setScale(0, RoundingMode.HALF_UP).toString());
                } else {
                    queryPortEntranceInfo.setCountTotal(new BigDecimal(0).toString());
                }
                portEntranceList.add(queryPortEntranceInfo);
            });
        }
        return portEntranceList;
    }

    private Object queryEntranceTrade(String startDateStr, String endDateStr) {
        return boatsVoyageMessageService.queryEntranceTrade(startDateStr, endDateStr);
    }

    /**
     * 月度到国内航次数量
     *
     * @return
     */
    public List<QueryMonthlyCountInfo> queryMonthlyShipCount(String startDate, String endDate) {
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(new Date());
//        calendar.add(Calendar.MONTH,-11);
//        Date time = calendar.getTime();
//        calendar.setTime(time);
//        calendar.set(Calendar.DAY_OF_MONTH, 1);
//        Date date = calendar.getTime();
//        String startDate = DateUtil.format(date, DatePattern.NORM_DATE_FORMATTER);
//        String endDate = DateUtil.format(new Date(), DatePattern.NORM_DATE_FORMATTER);
        List<QueryMonthlyCountInfo> resultList = new ArrayList<>();
        List<QueryMonthlyCountInfo> portList = boatsVoyageMessageService.queryMonthlyShipCount(startDate, endDate);
        if (CollectionUtil.isNotEmpty(portList)) {
            Map<String, List<QueryMonthlyCountInfo>> map = portList.stream().collect(Collectors.groupingBy(QueryMonthlyCountInfo::getDate));
            List<String> dateList = DateErgodicUtil.dateErgodicUtil(startDate, endDate);
            dateList.forEach(item -> {
                QueryMonthlyCountInfo queryMonthlyCountInfo = new QueryMonthlyCountInfo();
                queryMonthlyCountInfo.setDate(item);
                if (CollectionUtil.isNotEmpty(map.get(item))) {
                    QueryMonthlyCountInfo queryMonthlyCountInfo1 = map.get(item).get(0);
                    queryMonthlyCountInfo.setVoyageNumber(queryMonthlyCountInfo1.getVoyageNumber());
                }
                resultList.add(queryMonthlyCountInfo);
            });
        }
        logger.info("获取月度到国内航次数量统计返回结果:{}" + JSONUtil.parse(resultList));
        return resultList;
    }


    /**
     * 贸易量统计(单位：万吨)
     */
    public List<QueryVolumeTradeInfo> tradeVolumeStatistics(String startDate, String endDate) {
        List<QueryVolumeTradeInfo> volumeTradeList = new ArrayList<>();
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(new Date());
//        calendar.add(Calendar.MONTH,-11);
//        Date time = calendar.getTime();
//        calendar.setTime(time);
//        calendar.set(Calendar.DAY_OF_MONTH, 1);
//        Date date = calendar.getTime();
//        String startDate = DateUtil.format(date, DatePattern.NORM_DATE_FORMATTER);
//        String endDate = DateUtil.format(new Date(), DatePattern.NORM_DATE_FORMATTER);

        //查询出口量
        List<QueryBoatsVoyageMessagesInfo> boatsVoyageMessages = boatsVoyageMessageService.queryShipExportVolumeTotal(startDate, endDate);

        //查询进口量
        List<QueryBoatsVoyageMessagesInfo> dischargeCapacityList = boatsVoyageMessageService.queryDischargeCapacity(startDate, endDate);
        List<String> dateList = DateErgodicUtil.dateErgodicUtil(startDate, endDate);
        if (CollectionUtil.isNotEmpty(dateList)) {
            dateList.forEach(item -> {
                QueryVolumeTradeInfo queryVolumeTradeInfo = new QueryVolumeTradeInfo();
                queryVolumeTradeInfo.setDate(item);
                if (CollectionUtil.isNotEmpty(boatsVoyageMessages)) {
                    Map<String, List<QueryBoatsVoyageMessagesInfo>> map = boatsVoyageMessages.stream().collect(Collectors.groupingBy(QueryBoatsVoyageMessagesInfo::getTotalDate));
                    if (CollectionUtil.isNotEmpty(map.get(item))) {
                        BigDecimal exportVolumeTotal = map.get(item).get(0).getExportVolumeTotal();
                        if (exportVolumeTotal != null) {
                            BigDecimal result = exportVolumeTotal.divide(new BigDecimal(10000));
                            queryVolumeTradeInfo.setCarryingCapacity(result.setScale(0, RoundingMode.HALF_UP));
                        } else {
                            queryVolumeTradeInfo.setCarryingCapacity(new BigDecimal(0));
                        }
                    }
                }
                if (CollectionUtil.isNotEmpty(dischargeCapacityList)) {
                    Map<String, List<QueryBoatsVoyageMessagesInfo>> map = dischargeCapacityList.stream().collect(Collectors.groupingBy(QueryBoatsVoyageMessagesInfo::getTotalDate));
                    if (CollectionUtil.isNotEmpty(map.get(item))) {
                        BigDecimal exportVolumeTotal = map.get(item).get(0).getExportVolumeTotal();
                        if (exportVolumeTotal != null) {
                            BigDecimal result = exportVolumeTotal.divide(new BigDecimal(10000));
                            queryVolumeTradeInfo.setDischargeCapacity(result.setScale(0, RoundingMode.HALF_UP));
                        } else {
                            queryVolumeTradeInfo.setCarryingCapacity(new BigDecimal(0));
                        }
                    }
                }
                volumeTradeList.add(queryVolumeTradeInfo);
            });
        }
        return volumeTradeList;
    }

    @Override
    public Object getStatistics(int type) {
        if (type == 1) {
            Object object = redisService.getCacheObject(CacheConstants.HOME_STATISTICS_DATA_INFO_KEY);
            if (object != null) {
                return object;
            }
        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.MONTH, -11);
        Date time = calendar.getTime();
        calendar.setTime(time);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        Date date = calendar.getTime();
        String startDateStr = DateUtil.format(date, DatePattern.NORM_DATE_FORMATTER);
        String endDateStr = DateUtil.format(new Date(), DatePattern.NORM_DATE_FORMATTER);

        Map<String, Object> resultMap = new HashedMap<>();
        resultMap.put("upNo1", this.queryNews());
        resultMap.put("right1", this.tradeVolumeStatistics(startDateStr, endDateStr));

        //船舶租金
        SmShipRentAnalysisBo analysisBo = new SmShipRentAnalysisBo();
        Date startDate = DateUtil.offsetMonth(new Date(), -11);
        Date endDate = new Date();
        analysisBo.setStartDate(startDate);
        analysisBo.setEndDate(endDate);
//        JsonResult rentStatistics = smShipRentService.analysisStatistics(analysisBo);
//        if (rentStatistics.getResultCode().intValue() == BaseResultCode.OK.getCode()) {
//            resultMap.put("left23", rentStatistics.getResultObject());
//        } else {
//            resultMap.put("left23", new LinkedList<>());
//        }
        resultMap.put("right2", this.shipPortEntranceVolume(startDateStr, endDateStr));
        resultMap.put("right3", this.shipPortExportVolume(startDateStr, endDateStr));
        resultMap.put("bottom1", this.queryEntranceTrade(startDateStr, endDateStr));//top5进口贸易流向
        resultMap.put("bottom2", this.queryMonthlyShipCount(startDateStr, endDateStr));//月度到国内航次数量
        resultMap.put("bottom3",this.queryShipCountryInside(startDateStr, endDateStr));//国内top5进口港及进口量

//        String rightStartDateStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", startDate);
//        String rightEndDateStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", endDate);
//        resultMap.put("right1", this.queryTotalByShipStatus(rightStartDateStr, rightEndDateStr));

//        resultMap.put("right3", this.queryExecutionComplete(rightStartDateStr, rightEndDateStr));

        redisService.setCacheObject(CacheConstants.HOME_STATISTICS_DATA_INFO_KEY, resultMap);
        return resultMap;
    }

    private String queryNews() {
        //查询全球LNG船数量
        Integer number = informationListMapper.countShipNumber();
        //获取当前年份
        String date = DateUtil.format(new Date(), DatePattern.NORM_YEAR_PATTERN);
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MONTH, Calendar.JANUARY);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        String startDate = DateUtil.format(calendar.getTime(), DatePattern.NORM_DATE_FORMATTER);
        String endDate = DateUtil.format(new Date(), DatePattern.NORM_DATE_FORMATTER);
        String importVolume = "0";
        String exportVolume = "0";
        //获取当前年度进口量
        List<QueryBoatsVoyageMessagesInfo> dischargeCapacityList = boatsVoyageMessageService.queryDischargeCapacity(startDate, endDate);
        if (CollectionUtil.isNotEmpty(dischargeCapacityList)){
            BigDecimal importTotal = BigDecimal.ZERO;
            for (QueryBoatsVoyageMessagesInfo queryBoatsVoyageMessagesInfo : dischargeCapacityList) {
                if (null != queryBoatsVoyageMessagesInfo.getExportVolumeTotal()) {
                    importTotal = importTotal.add(queryBoatsVoyageMessagesInfo.getExportVolumeTotal());
                }
            }
            if (importTotal.compareTo(BigDecimal.ZERO) > 0){
                BigDecimal result = importTotal.divide(new BigDecimal(10000));
                importVolume = result.setScale(0, RoundingMode.HALF_UP).toString();
            }
        }
        //获取当前年度出口量
        List<QueryBoatsVoyageMessagesInfo> boatsVoyageMessages = boatsVoyageMessageService.queryShipExportVolumeTotal(startDate, endDate);
        if (CollectionUtil.isNotEmpty(boatsVoyageMessages)){
            BigDecimal exportTotal = BigDecimal.ZERO;
            for (QueryBoatsVoyageMessagesInfo queryBoatsVoyageMessagesInfo : boatsVoyageMessages) {
                if (null != queryBoatsVoyageMessagesInfo.getExportVolumeTotal()) {
                    exportTotal = exportTotal.add(queryBoatsVoyageMessagesInfo.getExportVolumeTotal());
                }
            }
            if (exportTotal.compareTo(BigDecimal.ZERO) > 0){
                BigDecimal result = exportTotal.divide(new BigDecimal(10000));
                exportVolume = result.setScale(0, RoundingMode.HALF_UP).toString();
            }
        }

        //查询中国已进口航次
        Integer shipNumber = boatsVoyageMessageService.queryVoyageNumberByChina(startDate,endDate);
        //查询中国进口量
        String volumeTotal = "0";
        Integer exportVolumeTotal = boatsVoyageMessageService.queryExportVolumeTotal(startDate,endDate);
        if (exportVolumeTotal > 0){
            BigDecimal result = new BigDecimal(exportVolumeTotal).divide(new BigDecimal(10000));
            volumeTotal = result.setScale(0, RoundingMode.HALF_UP).toString();
        }
        //查询在租LNG船
        Integer rentShipNumber = conShippingService.queryRentShipNumber(endDate);
        //查询已完成运输船次
        Integer transportShipNumber = spDispatchSchemeExecuteService.queryTransportShipNumber();
        //累计执行数量
        String carryOutNumber = spDispatchSchemeExecuteService.queryCarryOutNumber();

        //查询新闻
        SyNewRecord syNewRecord = syNewRecordService.selectNewRecord();
        String newRecord = syNewRecord != null ? syNewRecord.getNewContent() : "无";
        DecimalFormat decimalFormat = new DecimalFormat("#,###.###");
//        return "全球LNG船舶共 "+decimalFormat.format(new BigDecimal(number).setScale(0, RoundingMode.HALF_UP))+
//                " 艘，【"+date+
//                "】年进口量"+decimalFormat.format(new BigDecimal(importVolume).setScale(0, RoundingMode.HALF_UP))+
//                "万吨,出口量"+decimalFormat.format(new BigDecimal(exportVolume).setScale(0, RoundingMode.HALF_UP))+
//                "万吨，中国已进口【"+decimalFormat.format(new BigDecimal(shipNumber).setScale(0, RoundingMode.HALF_UP))+
//                "】船次，进口量"+decimalFormat.format(new BigDecimal(volumeTotal).setScale(0, RoundingMode.HALF_UP))+
//                "万吨，当前在租LNG船舶【"+decimalFormat.format(new BigDecimal(rentShipNumber).setScale(0, RoundingMode.HALF_UP))+
//                "】艘，已完成运输【"+decimalFormat.format(new BigDecimal(transportShipNumber).setScale(0, RoundingMode.HALF_UP))+
//                "】船次，累计执行"+decimalFormat.format(new BigDecimal(carryOutNumber).setScale(0, RoundingMode.HALF_UP))+
//                "万吨。【"+newRecord+
//                "】";

        return "全球LNG船舶共 "+decimalFormat.format(new BigDecimal(number).setScale(0, RoundingMode.HALF_UP))+
                " 艘，当前在租LNG船舶 "+decimalFormat.format(new BigDecimal(rentShipNumber).setScale(0, RoundingMode.HALF_UP))+
                " 艘，已完成运输 "+decimalFormat.format(new BigDecimal(transportShipNumber).setScale(0, RoundingMode.HALF_UP))+
                " 船次，累计执行 "+decimalFormat.format(new BigDecimal(carryOutNumber).setScale(0, RoundingMode.HALF_UP))+
                " 万吨。"+newRecord;
    }
//    全球LNG船舶共 123 艘，当前在租LNG船舶 4 艘，已完成运输 5 船次，累计执行 7 万吨。新闻
    // 1.船舶名称
    // 2.船舶信息（发动机类型+舱容+满载蒸发率+空载蒸发率）
    // 3.AIS状态
    // 4.租期
    // 5.上一航次
    // 6.当前航次
    @Override
    public List<ConHomePageShow> getShipInfo() throws ParseException {
        //获取1 2 3 4的信息
        List<String> conIdList = conHomePageServer.getAllConId();
        List<ConHomePageAll> conShippingList = conHomePageServer.getByConIdList(conIdList);

        List<ConHomePageShow> conHomePageShowList = new ArrayList<>();
        // 去除多余字段
        for (ConHomePageAll conHomePageAll : conShippingList) {
            ConHomePageShow conHomePageShow = new ConHomePageShow();

            BeanUtils.copyProperties(conHomePageAll, conHomePageShow);
            conHomePageShowList.add(conHomePageShow);
        }
        
        // 上一个航次
        List<Map<String,String>> lastVoyage = conHomePageServer.getLastVoyage();
        if (lastVoyage != null && !lastVoyage.isEmpty()) {

            // 构建 shipName 到 value 的映射
            Map<String, String> lastVoyageMap = new HashMap<>();
            for (Map<String, String> voyage : lastVoyage) {
                String shipName = voyage.get("shipName");
                System.out.println("shipName1：" + shipName);
                String value = voyage.get("value");
                lastVoyageMap.put(shipName, value);
            }

            // 将 lastVoyage 中的 value 填充到 conHomePageShowList 中的 lastVoyage 字段
            for (ConHomePageShow conHomePageShow : conHomePageShowList) {
                String shipName = conHomePageShow.getShipName();
                System.out.println("shipName2：" + shipName);
                if (lastVoyageMap.containsKey(shipName)) {
                    conHomePageShow.setLastVoyage(lastVoyageMap.get(shipName));
                }
            }

//            System.out.println("lastVoyage:" + lastVoyage);
        }
        //当前航次
        List<String> imolist = conShippingList.stream()
                .map(ConHomePageAll::getImo)
                .collect(Collectors.toList());
        List<Map<String,String>> nowVoyage = conHomePageServer.getNowVoyage(imolist);
        if (nowVoyage != null && !nowVoyage.isEmpty()) {

            // 构建 shipName 到 value 的映射
            Map<String, String> nowVoyageMap = new HashMap<>();
            for (Map<String, String> voyage : nowVoyage) {
                String shipName = voyage.get("shipName");
//                System.out.println("shipName1：" + shipName);
                String value = voyage.get("value");
                nowVoyageMap.put(shipName, value);
            }

            // 将 nowVoyage 中的 value 填充到 conHomePageShowList 中的 nowVoyage 字段
            for (ConHomePageShow conHomePageShow : conHomePageShowList) {
                String shipName = conHomePageShow.getShipName();
//                System.out.println("shipName2：" + shipName);
                if (nowVoyageMap.containsKey(shipName)) {
                    conHomePageShow.setNowVoyage(nowVoyageMap.get(shipName));
                }
            }

//            System.out.println("nowVoyage:" + nowVoyage);
        }

        return conHomePageShowList;
    }

}
